"""
hooks  作用：
1、对请求对象的预处理
2、对返回对象的预处理

request 库 hooks参数，只有一个response  返回的钩子(没有请求钩子)
"""

import requests
from requests import Response

url = 'http://www.example.com/'


def response_status(response: Response, *args, **kwargs):
    """响应 预处理 hook功能"""
    print(f"响应的url：{response.url}")
    # 给response添加的属性
    response.status = 'PASS'
    if response.status_code < 400:
        response.status = 'PASS'
    else:
        response.status = 'FAIL'


r1 = requests.request(
    method='get',
    url=url,
    hooks={'response': response_status}  # 传函数对象
)
r1.status_code = 500

print(r1.status_code)
print(r1.status)
